<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/markdown-it@12.0.6/dist/markdown-it.min.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const baseActivity = {
          from: {
            id: 'bot',
            role: 'bot'
          },
          textFormat: 'markdown',
          timestamp: new Date(2000, 0, 1, 12, 34, 56, 789).toISOString(),
          type: 'message'
        };

        const markdownIt = markdownit({ html: true });

        WebChat.renderWebChat(
          {
            directLine: testHelpers.createDirectLineWithTranscript([
              {
                ...baseActivity,
                text: '![Exclamation mark]() Warning.'
              },
              {
                ...baseActivity,
                text: '- Hello\n- World\n  - Aloha'
              },
              {
                ...baseActivity,
                text: 'Hello\n\nWorld'
              },
              {
                ...baseActivity,
                text: '<table><tr><td>USD</td><td>1.00</td></tr><tr><td>JPY</td><td>0.91</td></tr></table>'
              },
              {
                ...baseActivity,
                text: 'Hello, <strong>World</strong>!'
              },
              {
                ...baseActivity,
                text: 'Hello, <a href="https://bing.com/">Bing</a>!'
              }
            ]),
            renderMarkdown: markdownIt.render.bind(markdownIt),
            store: testHelpers.createStore(),
            styleOptions: {
              internalLiveRegionFadeAfter: 60000
            }
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();
        await pageConditions.numActivitiesShown(6);
        await pageConditions.liveRegionStabilized();

        const screenReaderTexts = [].map.call(pageElements.liveRegion().children, child =>
          testHelpers.getAllTextContents(child).join('\n')
        );

        expect(screenReaderTexts).toEqual([
          'connecting',
          'Bot said:\nExclamation mark Warning.',
          'Bot said:\nHello\nWorld\nAloha',
          'Bot said:\nHello\nWorld',
          'Bot said:\nUSD\n1.00\nJPY\n0.91',
          'Bot said:\nHello, World!',
          'Bot said:\nHello, Bing!',
          'One or more links in the message. Press shift tab key 2 to 3 times to switch to the chat history. Then click on the message to interact.'
        ]);

        // The screenshot should show the message in Markdown format, i.e. <strong> and <code>.
        await host.snapshot('local');
      });
    </script>
  </body>
</html>
